package com.burstly.lib.component.networkcomponent.greystripe;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import com.burstly.lib.component.AbstractAdaptor;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.LayoutParametersResolver;
import com.burstly.lib.util.LoggerExt;
import com.greystripe.sdk.GSAd;
import com.greystripe.sdk.GSAdErrorCode;
import com.greystripe.sdk.GSAdListener;
import com.greystripe.sdk.GSFullscreenAd;
import com.greystripe.sdk.GSLeaderboardAdView;
import com.greystripe.sdk.GSMediumRectangleAdView;
import com.greystripe.sdk.GSMobileBannerAdView;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Map;

final class GreystripeAdaptor extends AbstractAdaptor
{
  static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("greystripe", true);
  static final String NETWORK_NAME = "greystripe";
  private final GreystripeConfigurator mConfigurator;
  private final GSAdListener mListener = new GSListener(this);
  private GSFullscreenAd mPrecachedInterstitial;

  GreystripeAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " GreystripeAdaptor");
    this.mConfigurator = new GreystripeConfigurator();
  }

  private View wrap(View paramView)
  {
    paramView.setLayoutParams(getLayoutParamsResolver().resolveParameters());
    RelativeLayout localRelativeLayout = new RelativeLayout(getContext());
    localRelativeLayout.setGravity(17);
    localRelativeLayout.addView(paramView);
    return localRelativeLayout;
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    this.mConfigurator.initConfigurator(paramMap);
    this.mConfigurator.updateLocation(getContext());
  }

  public void destroy()
  {
    super.destroy();
    this.mPrecachedInterstitial = null;
  }

  protected View doGetNewAd()
  {
    this.mPrecachedInterstitial = null;
    String str1 = this.mConfigurator.getAppId();
    LOG.logInfo(this.mTag, "appID for Greystripe: {0}", new Object[] { str1 });
    String str2 = this.mConfigurator.getAdSize();
    Object localObject;
    if ("320x50".equals(str2))
    {
      GSMobileBannerAdView localGSMobileBannerAdView = new GSMobileBannerAdView(getContext(), str1);
      localGSMobileBannerAdView.addListener(this.mListener);
      localGSMobileBannerAdView.refresh();
      localObject = localGSMobileBannerAdView;
    }
    while (true)
    {
      View localView = null;
      if (localObject != null)
        localView = wrap((View)localObject);
      return localView;
      if ("300x250".equals(str2))
      {
        GSMediumRectangleAdView localGSMediumRectangleAdView = new GSMediumRectangleAdView(getContext(), str1);
        localGSMediumRectangleAdView.addListener(this.mListener);
        localGSMediumRectangleAdView.refresh();
        localObject = localGSMediumRectangleAdView;
      }
      else if ("728x90".equals(str2))
      {
        GSLeaderboardAdView localGSLeaderboardAdView = new GSLeaderboardAdView(getContext(), str1);
        localGSLeaderboardAdView.addListener(this.mListener);
        localGSLeaderboardAdView.refresh();
        localObject = localGSLeaderboardAdView;
      }
      else
      {
        GSFullscreenAd localGSFullscreenAd = new GSFullscreenAd(getContext(), str1);
        localGSFullscreenAd.addListener(this.mListener);
        localGSFullscreenAd.fetch();
        localObject = null;
      }
    }
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    if (this.mConfigurator.isInterstitial())
      return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public String getNetworkName()
  {
    return "greystripe";
  }

  public View precacheAd()
  {
    return getNewAd();
  }

  public void precacheInterstitialAd()
  {
    String str = this.mConfigurator.getAppId();
    LOG.logInfo(this.mTag, "pubID for Greystripe: {0}", new Object[] { str });
    this.mPrecachedInterstitial = new GSFullscreenAd(getContext(), str);
    this.mPrecachedInterstitial.addListener(this.mListener);
    this.mPrecachedInterstitial.fetch();
  }

  public void showPrecachedInterstitialAd()
  {
    if (this.mPrecachedInterstitial != null)
    {
      IBurstlyAdaptorListener localIBurstlyAdaptorListener = getAdaptorListener();
      localIBurstlyAdaptorListener.didLoad("greystripe", true);
      localIBurstlyAdaptorListener.shownFullscreen(FULLSCREEN_INFO);
      this.mPrecachedInterstitial.display();
      this.mPrecachedInterstitial = null;
    }
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  private static class GSListener
    implements GSAdListener
  {
    private final Reference<GreystripeAdaptor> mAdaptor;

    GSListener(GreystripeAdaptor paramGreystripeAdaptor)
    {
      this.mAdaptor = new WeakReference(paramGreystripeAdaptor);
    }

    public void onAdClickthrough(GSAd paramGSAd)
    {
      GreystripeAdaptor localGreystripeAdaptor = (GreystripeAdaptor)this.mAdaptor.get();
      if ((localGreystripeAdaptor != null) && (!localGreystripeAdaptor.isStopped()))
      {
        boolean bool = paramGSAd instanceof GSFullscreenAd;
        localGreystripeAdaptor.getAdaptorListener().adWasClicked("greystripe", bool);
      }
    }

    public void onAdCollapse(GSAd paramGSAd)
    {
      GreystripeAdaptor localGreystripeAdaptor = (GreystripeAdaptor)this.mAdaptor.get();
      if ((localGreystripeAdaptor != null) && (!localGreystripeAdaptor.isStopped()))
        localGreystripeAdaptor.getAdaptorListener().onCollapse("greystripe");
    }

    public void onAdDismissal(GSAd paramGSAd)
    {
      if ((paramGSAd instanceof GSFullscreenAd))
      {
        GreystripeAdaptor localGreystripeAdaptor = (GreystripeAdaptor)this.mAdaptor.get();
        if ((localGreystripeAdaptor != null) && (!localGreystripeAdaptor.isStopped()))
          localGreystripeAdaptor.getAdaptorListener().dismissedFullscreen(GreystripeAdaptor.FULLSCREEN_INFO);
      }
    }

    public void onAdExpansion(GSAd paramGSAd)
    {
      GreystripeAdaptor localGreystripeAdaptor = (GreystripeAdaptor)this.mAdaptor.get();
      if ((localGreystripeAdaptor != null) && (!localGreystripeAdaptor.isStopped()))
        localGreystripeAdaptor.getAdaptorListener().onExpand("greystripe", true);
    }

    public void onFailedToFetchAd(GSAd paramGSAd, GSAdErrorCode paramGSAdErrorCode)
    {
      GreystripeAdaptor localGreystripeAdaptor = (GreystripeAdaptor)this.mAdaptor.get();
      if ((localGreystripeAdaptor != null) && (!localGreystripeAdaptor.isStopped()))
      {
        boolean bool = paramGSAd instanceof GSFullscreenAd;
        GreystripeAdaptor.LOG.logInfo(localGreystripeAdaptor.mTag, "Failed to receive Greystripe ad...", new Object[0]);
        localGreystripeAdaptor.getAdaptorListener().failedToLoad("greystripe", bool, paramGSAdErrorCode.name());
      }
    }

    public void onFetchedAd(GSAd paramGSAd)
    {
      GreystripeAdaptor localGreystripeAdaptor = (GreystripeAdaptor)this.mAdaptor.get();
      if ((localGreystripeAdaptor != null) && (!localGreystripeAdaptor.isStopped()))
      {
        boolean bool = paramGSAd instanceof GSFullscreenAd;
        localGreystripeAdaptor.getAdaptorListener().didLoad("greystripe", bool);
        if ((localGreystripeAdaptor.mPrecachedInterstitial == null) && (bool))
        {
          ((GSFullscreenAd)paramGSAd).display();
          localGreystripeAdaptor.getAdaptorListener().shownFullscreen(GreystripeAdaptor.FULLSCREEN_INFO);
        }
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.greystripe.GreystripeAdaptor
 * JD-Core Version:    0.6.2
 */